package com.example.oasystem.dao.task;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.oasystem.entity.status.AoaStatusList;
import com.example.oasystem.entity.task.AoaTaskList;
import com.example.oasystem.entity.task.AoaTaskLogger;
import com.example.oasystem.entity.task.AoaTaskUser;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AoaTaskListDao extends BaseMapper<AoaTaskList> {
    //查询自己的任务
    List<AoaTaskList> findMyTask(int id);
    //查询自己的任务baseKey
    List<AoaTaskList> findMyTaskAndBaseKey(int id,String baseKey);

    AoaTaskList selectOne(int uid,int taskId);

    @Select("select * from aoa_task_list t , aoa_task_logger l " +
            "where t.task_id = #{taskId} and t.task_id = l.task_id")
    List<AoaTaskLogger> findAllLogger(int taskId);

    /**
     * 查找所有的状态
     * @return
     */
    @Select("select * from aoa_status_list")
    List<AoaStatusList> findAllStatus();


    /**
     * 查找3，4，5，6对应的状态记录
     * @return
     */
    @Select("select * from aoa_status_list where status_id=3 or status_id=4 or status_id=5 or status_id=6")
    List<AoaStatusList> findAllStatus2();
    //添加新的日志
    @Insert("insert into aoa_task_logger(create_time,logger_ticking,task_id,username,logger_statusid) values(#{time},#{loggerTicking},#{taskId},#{userName},#{loggerStatusid})")
    int insertLogger(@Param("time")String time, @Param("loggerStatusid")int loggerStatusid, @Param("loggerTicking")String loggerTicking, @Param("taskId")int taskId, @Param("userName")String userName);
    //
    @Select("select * from aoa_task_user where task_id =#{taskId}")
    List<AoaTaskUser> findAllTaskUserByTaskId(@Param("taskId")String taskId);

    @Update("update aoa_task_user set status_id=#{loggerStatusid} where task_id=#{taskId} and task_recive_user_id =#{userid}")
    int updateTaskUser(@Param("loggerStatusid")int loggerStatusid,@Param("taskId")int taskId,@Param("userid") String userid);

    @Update("update aoa_task_list set status_id=#{Statusid} where task_id=#{taskId}")
    int updateTaskList(@Param("Statusid")int Statusid,@Param("taskId")int taskId);

    @Delete("delete from aoa_task_user where task_id=#{id} and task_recive_user_id=${userid}" )
    int delTask(int id,Long userid);

    @Delete("delete from aoa_task_list where task_id=#{taskId};")
    int deleteTaskById(int taskId);

}